package xx.iverson.school_manage.controller;


import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import xx.iverson.school_manage.entity.User;
import xx.iverson.school_manage.service.OperationRecordService;
import xx.iverson.school_manage.service.PointsService;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * @author wei77
 */
@Controller
public class ToUserController {

    @Resource
    private PointsService pointsService;

    @Resource
    private OperationRecordService operationRecordService;


    // 跳转到修改密码页面
    @RequestMapping("toUpdate")
    public String toUpdate() {
        return "user/me";
    }

    // 跳转到老师首页
    @RequestMapping("toIndex")
    public String toIndex(Model model, HttpSession session) {
        User user = (User) session.getAttribute("user");
        model.addAttribute("rank", pointsService.getRank(user.getUserId()));
        model.addAttribute("points", pointsService.getListPoints(30));
        return "user/index";
    }

    // 跳转到积分记录页面
    @RequestMapping("toRecord")
    public String toPointsRecord(Model model, HttpSession session) {
        User user = (User) session.getAttribute("user");
        model.addAttribute("records", operationRecordService.getOperationRecords(user.getUserId()));
        return "user/record";
    }
}
